﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace BGSpaceShooterServer
{
    public class Server
    {
        public event LogEventHandler MessageAppeared;

        /// <summary>
        /// Promień BoundingSphere'a dla asteriod. Docelowo do XML'a
        /// </summary>
        public static float AsteroidBoundingSphereRadius { get { return ProjectileContainer.asteroidBoundingSphereRadius; } }

        /// <summary>
        /// Promień BoundingSphere'a dla pocisków. Docelowo do XML'a
        /// </summary>
        public static float BulletBoundingSphereRadius { get { return ProjectileContainer.bulletBoundingSphereRadius; } }

        public Server()
        {
            Logger.LogMessageAppeared += new LogEventHandler(logMessageAppeared);
        }

        private void logMessageAppeared(object obj, LogEventArgs logEventArgs)
        {
            if (MessageAppeared != null)
            {
                MessageAppeared.Invoke(this, logEventArgs);
            }
        }

        private Router Router
        {
            get;
            set;
        }

        public string[] GetCurrentIPs()
        {
            return NetworkController.GetIPs();
        }

        public void InitializeGame(int maxPlayers, int port)
        {
            Router = Router.StartRouter(maxPlayers, port);
            Router.ServerState = ServerState.Initialization;
        }

        public void StartGame()
        {
            if (Router != null)
            {
                Router.ServerState = ServerState.Game;
            }
        }

        public void EndGame()
        {
            if (Router != null)
            {
                Router.ServerState = ServerState.Exiting;
            }
        }
    }
}
